//
//  controller.h
//  cocoa_client
//
//  Created by ixtli on 7/30/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <sys/socket.h>
#import <netinet/in.h>
#import <netinet/in.h>
#import <arpa/inet.h>
#import <errno.h>

@interface controller : NSObject {

	NSFileHandle *_listeningSocket;
	NSString *_userName;
	NSString *_password;
	
	unsigned int _sockfd;
	BOOL _connected;
	BOOL _debug;
	
	IBOutlet NSTextView *_logView;
	IBOutlet NSButton *_connectButton;
	IBOutlet NSTextField *_portField;
	IBOutlet NSTextField *_hostField;
	IBOutlet NSTextField *_nameField;
	IBOutlet NSTextField *_passField;
	IBOutlet NSTextField *_messageField;
	IBOutlet NSScrollView *_scrollView;
}

- (void)setupService;
- (void)stopService;
- (BOOL)isConnected;

- (void)writeToLog:(NSString*)message;
- (void)debug:(NSString*)message;
- (void)error:(NSString *)message;
- (void)scrollToBottom:(id)sender;
- (void)writeServerMessageToLog:(response_types)type previousAction:(client_actions)action serverError:(server_error)error;

- (IBAction)toggleDebugOutput:(id)sender;
- (IBAction)sendMessage:(id)sender;
- (IBAction)toggleConnect:(id)sender;
- (IBAction)createAccount:(id)sender;

@end

@interface controller (NotificationHandling)

- (void)handleServerMessage:(NSNotification *)notification;

@end
